<?php require_once('Connections/hitekforyou.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');

// Load the tNG classes
require_once('includes/tng/tNG.inc.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");

// Make unified connection variable
$conn_hitekforyou = new KT_connection($hitekforyou, $database_hitekforyou);

//start Trigger_SendEmail trigger
//remove this line if you want to edit the code by hand
function Trigger_SendEmail(&$tNG) {
  $emailObj = new tNG_Email($tNG);
  $emailObj->setFrom("{POST.email}");
  $emailObj->setTo("nguyen.dct1094@gmail.com");
  $emailObj->setCC("");
  $emailObj->setBCC("");
  $emailObj->setSubject("{POST.tieude}");
  //FromFile method
  $emailObj->setContentFile("lienhe_noidungthu.html");
  $emailObj->setEncoding("UTF-8");
  $emailObj->setFormat("HTML/Text");
  $emailObj->setImportance("Normal");
  return $emailObj->Execute();
}
//end Trigger_SendEmail trigger

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_sanpham = 12;
$pageNum_sanpham = 0;
if (isset($_GET['pageNum_sanpham'])) {
  $pageNum_sanpham = $_GET['pageNum_sanpham'];
}
$startRow_sanpham = $pageNum_sanpham * $maxRows_sanpham;

mysql_select_db($database_hitekforyou, $hitekforyou);
$query_sanpham = "SELECT * FROM sanpham WHERE AnHien = 1 ORDER BY idSP DESC";
$query_limit_sanpham = sprintf("%s LIMIT %d, %d", $query_sanpham, $startRow_sanpham, $maxRows_sanpham);
$sanpham = mysql_query($query_limit_sanpham, $hitekforyou) or die(mysql_error());
$row_sanpham = mysql_fetch_assoc($sanpham);

if (isset($_GET['totalRows_sanpham'])) {
  $totalRows_sanpham = $_GET['totalRows_sanpham'];
} else {
  $all_sanpham = mysql_query($query_sanpham);
  $totalRows_sanpham = mysql_num_rows($all_sanpham);
}
$totalPages_sanpham = ceil($totalRows_sanpham/$maxRows_sanpham)-1;


$queryString_sanpham = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_sanpham") == false && 
        stristr($param, "totalRows_sanpham") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_sanpham = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_sanpham = sprintf("&totalRows_sanpham=%d%s", $totalRows_sanpham, $queryString_sanpham);

// Make a logout transaction instance
$logoutTransaction = new tNG_logoutTransaction($conn_hitekforyou);
$tNGs->addTransaction($logoutTransaction);
// Register triggers
$logoutTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "thoat");
$logoutTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "Index.php");
// Add columns
// End of logout transaction instance

// Make a custom transaction instance
$customTransaction = new tNG_custom($conn_hitekforyou);
$tNGs->addTransaction($customTransaction);
// Register triggers
$customTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "nutgui");
$customTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "index.php");
$customTransaction->registerTrigger("AFTER", "Trigger_SendEmail", 98);
// Add columns
// End of custom transaction instance

// Make a login transaction instance
$loginTransaction = new tNG_login($conn_hitekforyou);
$tNGs->addTransaction($loginTransaction);
// Register triggers
$loginTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "dangnhap");
$loginTransaction->registerTrigger("END", "Trigger_Default_Redirect", 99, "{kt_login_redirect}");
$loginTransaction->registerTrigger("AFTER", "Trigger_SendEmail", 98);
// Add columns
$loginTransaction->addColumn("kt_login_user", "STRING_TYPE", "POST", "user_name");
$loginTransaction->addColumn("kt_login_password", "STRING_TYPE", "POST", "user_pass");
// End of login transaction instance

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rscustom = $tNGs->getRecordset("custom");
$row_rscustom = mysql_fetch_assoc($rscustom);
$totalRows_rscustom = mysql_num_rows($rscustom);


$TFM_LimitLinksEndCount = 12;
$TFM_temp = $pageNum_sanpham + 1;
$TFM_startLink = max(1,$TFM_temp - intval($TFM_LimitLinksEndCount/2));
$TFM_temp = $TFM_startLink + $TFM_LimitLinksEndCount - 1;
$TFM_endLink = min($TFM_temp, $totalPages_sanpham + 1);
if($TFM_endLink != $TFM_temp) $TFM_startLink = max(1,$TFM_endLink - $TFM_LimitLinksEndCount + 1);


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trang chủ</title>
<link href="css.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="stmenu.js"></script>
<script src="AC_RunActiveContent.js" type="text/javascript"></script>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
</head>

<body>
<div id="container">
  <div id="header">
   <?php include("banner.php"); ?> 
  </div>
  <div id="menu">
   <script type="text/javascript" src="menu.js"></script>

  </div>
  <div id="main">
    <!-- Start Div Left Main -->
    <?php include("leftmain.php"); ?>
        <!-- End Div Left Main -->
    <!-- Start Div right Main -->
   <div id="rightmain">


    <?php
//Show If User Is Logged In (region1)
$isLoggedIn = new tNG_UserLoggedIn($conn_hitekforyou);
//Grand Levels: Level
if ($isLoggedIn->Execute()) {
?>
<form id="DangXuat" name="dangxuat" method="post" action="">
          <table width="184" border="0" cellspacing="0" cellpadding="0" align="center">
            <tbody>
              <tr>
                <td align="center"><img src="images/dang-nhap.jpg" alt="6" width="184" height="41" /></td>
              </tr>
              <tr>
                <td height="170" valign="top" background="images/dang-nhap-bg.jpg" style="padding:5px 5px 5px 5px; background-repeat:no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                              <tr>
                                <td><div align="center"><strong>Chào
                                    <?php echo $_SESSION['kt_TenKH']; ?> </strong></div></td>
                              </tr>
                              <tr>
                                <td height="8"><img src="images/spacer.gif" alt="5" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center"><strong><a href="doithongtincanhan.php" class="lienket">Đổi thông tin cá nhân</a></strong></div></td>
                              </tr>
                              <tr>
                                <td height="5"><img  src="images/spacer.gif" alt="4" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center">
                                  </div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" alt="3" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                              </tr>
                              <tr>
                                <td height="5"><img  src="images/spacer.gif" alt="2" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td height="5" align="center"><?php
	echo $tNGs->getErrorMsg();
?><input type="submit" name="thoat" id="button2" value="Thoát" onclick="funABC()" /></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" alt="1" width="1" height="1" /></td>
                              </tr>
                            </tbody>
                        </table></td>
                      </tr>
                      <tr>
                        <td valign="top"><label>
                            <div align="center"></div>
                          </label></td>
                      </tr>
                    </tbody>
                  </table>
                    <label>
                    <div align="center"></div>
                  </label></td>
              </tr>
            </tbody>
          </table>
            </form>


      <?php 
// else Show If User Is Logged In (region1)
} else { ?>
      <form id="DangNhap" name="DangNhap" method="post" action="">
          <table width="184" border="0" cellspacing="0" cellpadding="0" align="center">
            <tbody>
              <tr>
                <td align="center"><img src="images/dang-nhap.jpg" width="184" height="41" /></td>
              </tr>
              <tr>
                <td height="170" valign="top" background="images/dang-nhap-bg.jpg" style="padding:5px 5px 5px 5px; background-repeat:no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tbody>
                      <tr>
                        <td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
                            <tbody>
                              <tr>
                                <td><div align="center"><strong>Tên đăng nhập</strong></div></td>
                              </tr>
                              <tr>
                                <td height="8"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center">
                                  <input type="text" name="user_name" id="user_name" />
                                </div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center"><strong>Mật khẩu</strong></div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td><div align="center">
                                  <input type="password" name="user_pass" id="user_pass" />
                                </div></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                              <tr>
                                <td height="5" align="center"><input type="submit" name="dangnhap" id="button" value="Đăng nhập" /></td>
                              </tr>
                              <tr>
                                <td height="5"><img src="images/spacer.gif" width="1" height="1" /></td>
                              </tr>
                            </tbody>
                        </table></td>
                      </tr>
                    </tbody>
                  </table>
                    <label>
                    <div align="center"></div>
                  </label></td>
              </tr>
            </tbody>
          </table>
        </form> <!-- End Form Đăng nhập -->
  <?php
}
//End Show If User Is Logged In (region1)
?>


        
      <table width="184" border="0" cellspacing="0" cellpadding="0" align="center">
        <tbody>
          <tr>
            <td align="center"><img src="images/tin-moi-nhat.jpg" width="184" height="40" /></td>
          </tr>
          <tr>
            <td height="226" valign="top" background="images/tin-moi-nhat-bg.jpg" style="padding:5px 5px 5px 5px; background-repeat:no-repeat;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tbody>
                  <tr>
                    <td>
<div style="height:200px;">
<marquee behavior="scroll" direction="up" height="200px" scrolldelay="700">
<div style="padding-bottom:2px; padding-top:5px;padding-left:5px;"><img src="images/arrow2.gif" width="9" height="7" />Tin mới</div>
</marquee>
</div></td>
                  </tr>
                </tbody>
            </table></td>
          </tr>
        </tbody>
      </table> <!-- End Table Tin tuc -->
    </div>
        <!-- End Div right Main -->
    <div id="content">
    <form action="index.php" method="post" enctype="multipart/form-data" name="formlienhe" id="formlienhe">
  <table width="600" border="1" align="center" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF">
  
  <tr class="tieude">
    <td height="70" colspan="2"><div align="center">Liên hệ</div></td>
    </tr>
  <tr>
      <td width="80">Họ tên</td>
      <td><input name="hoten" type="text" class="dangky" id="hoten" /></td>
    </tr>
    <tr>
      <td>Email</td>
      <td><input name="email" type="text" class="dangky" id="email" /></td>
    </tr>
    <tr>
      <td>Địa chỉ</td>
      <td><input name="diachi" type="text" class="dangky" id="diachi" /></td>
    </tr>
    <tr>
      <td>Số điện thoại</td>
      <td><input name="phone" type="text" class="dangky" id="phone" /></td>
    </tr>
    <tr>
      <td>Tiêu đề</td>
      <td><input name="tieude" type="text" class="dangky" id="tieude" /></td>
    </tr>
    <tr>
      <td valign="top">Nội dung</td>
      <td><textarea name="noidung" cols="45" rows="5" class="dangky" id="noidung"></textarea></td>
    </tr>
    
    <tr>
      <td colspan="2" align="center"><input type="submit" name="nutgui" id="nutgui" value="   Gửi   " />
       &nbsp; 
       <input type="reset" name="xoa" id="xoa" value="   Xóa   " />
      <input name="ngay" type="hidden" id="ngay" value="<? echo date('d/m/Y h:i:s'); ?>" /></td>
    </tr>
  </table>
  <div align="center"></div>
</form>
    </div> 
    <!-- End div content -->
  </div><!-- End div Main -->
  <div id="footer">
  <?php include("footer.php"); ?>
  </div>
</div>
</body>
</html>
<?php
mysql_free_result($sanpham);
?>
